Debian 9 Stretch
Sponsored Link

OpenStack Newton : Add VM-Images
2017/07/02
 
Add Virtual Machine images in Glance.
[1] For example, Create a Virtual Machine image of Debian 9.
root@dlp ~(keystone)#
apt -y install libguestfs-tools virt-top
# create a directory for disk image

root@dlp ~(keystone)#
mkdir -p /var/kvm/images
# create a disk image

root@dlp ~(keystone)#
qemu-img create -f qcow2 /var/kvm/images/debian9.img 10G
root@dlp ~(keystone)#
virsh net-start default

root@dlp ~(keystone)#
virt-install \
--name debian9 \
--ram 2048 \
--disk path=/var/kvm/images/debian9.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant debian9 \
--network network=default \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.jaist.ac.jp/pub/Linux/debian/dists/stretch/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'
Starting install...    
# installation starts
# after finishing installation, back to KVM Host and shutdown VM

root@dlp ~(keystone)#
virsh shutdown debian9
# mount the disk image of the VM

root@dlp ~(keystone)#
guestmount -d debian9 -i /mnt
# enable getty@ttyS0.service

root@dlp ~(keystone)#
ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service

# unmount and start

root@dlp ~(keystone)#
umount /mnt

root@dlp ~(keystone)#
virsh start debian9 --console
# configure some settings for openstack instance on VM

root@debian:~#
apt -y install ssh cloud-init
root@debian:~#
vi /etc/default/grub
# line 9: change like follows

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="
console=tty1 console=ttyS0
"
GRUB_CMDLINE_LINUX=""
# line 33,34: comment out

#
GRUB_TERMINAL=serial
#
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stopp=1"
root@debian:~#
update-grub
root@debian:~#
vi /etc/cloud/cloud.cfg
# near line 13: add (if you'd like to allow SSH password authentication to login)

ssh_pwauth: true
# line 87: change (if you'd like to allow [debian] user's SSH password auth)

default_user:
    name: debian
    lock_passwd:
False
root@debian:~#
vi /etc/network/interfaces
# comment out except loopback interface

# The primary network interface
#
auto ens2
#
iface ens2 inet dhcp
root@debian:~#
systemctl enable serial-getty@ttyS0.service
# shutdown to finish settings

root@debian:~#
shutdown -h now
[3] Add the virtual machine image to Glance.
root@dlp ~(keystone)#
openstack image create "Debian9" --file /var/kvm/images/debian9.img --disk-format qcow2 --container-format bare --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | b8f368fd71093b6b17c112fa8aca33b4                     |
| container_format | bare                                                 |
| created_at       | 2017-07-03T03:53:19Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/2a339775-723f-489d-ab6d-66308c750918/file |
| id               | 2a339775-723f-489d-ab6d-66308c750918                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | Debian9                                              |
| owner            | 5d0a67ea1741404aa057d1fdb6e4e1be                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 1684799488                                           |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-07-03T03:53:35Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

root@dlp ~(keystone)#
openstack image list

+--------------------------------------+---------+--------+
| ID                                   | Name    | Status |
+--------------------------------------+---------+--------+
| 2a339775-723f-489d-ab6d-66308c750918 | Debian9 | active |
+--------------------------------------+---------+--------+
[4] By the way, if you got an image from internet, it's OK to simply add it like follows.
root@dlp ~(keystone)#
wget http://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
root@dlp ~(keystone)#
openstack image create "Ubuntu1604" --file /var/kvm/images/ubuntu-16.04-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | fc5ad26274fcc42cfa32d97308613432                     |
| container_format | bare                                                 |
| created_at       | 2017-02-24T01:44:21Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/3113fc28-fa1f-4221-909e-a4fc5bdb8d6a/file |
| id               | 3113fc28-fa1f-4221-909e-a4fc5bdb8d6a                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | Ubuntu1604                                           |
| owner            | 3424019a88f34894b22058d6e15a8d35                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 324141056                                            |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-02-24T01:44:23Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
 
Tweet